import time

from spain.web.web import Web
from time import sleep
from src.appointment_ticket import AppointmentTicket
from src.appointment_utils import get_available_appointment_dates, get_available_slots_by_date
from src.email_helper import EmailHelper
from src.user import User
from src import utils
from src.visa_verification import VisaVerification

def main():
    Web.run()
    # while True:
    #     sleep(10000)

if __name__ == '__main__':
    # main()
    start_time = time.time()
    user_name = '1248198090@qq.com'
    password = '123$QWas'
    user = User(user_name=user_name, password=password)
    cookies = user.get_cookies()
    if cookies:
    #     end_time = time.time()
    #     # print(f'运行时间: {end_time - start_time} 秒')
    #
        VisaType = "3033c6d3-579b-47e1-9602-91368d63025c"
        AppointmentCategoryId = "5c2e8e01-796d-4347-95ae-0c95a9177b26"
        VisaSubType = "d6f2b878-181f-4584-a595-babdbcac4298"
        Location = "8d780684-1524-4bda-b138-7c71a8591944"
        AppointmentDate = '2024-04-25'
        AppointmentSlot = '08:00-08:30'
        verica = VisaVerification(cookies, VisaType, VisaSubType, AppointmentCategoryId, Location)
        html_content = verica.get_appoint_html()

        if html_content:
            with open('login.html', 'wb') as file:
                file.write(html_content)
    # 'https://spain.blscn.cn/CHN/bls/visatypeverification'
    #
            ticket = AppointmentTicket(html_content, AppointmentDate, AppointmentSlot, cookies, 'https://spain.blscn.cn/CHN/query/getfile?fileid=44684a8c-1915-4d60-af69-7fd2d36b8d7f')
            ticket.create()
    #






















    # locationId = '8d780684-1524-4bda-b138-7c71a8591944'
    # categoryId = '5c2e8e01-796d-4347-95ae-0c95a9177b26'
    # visaType = '3033c6d3-579b-47e1-9602-91368d63025c'
    # visaSubType = 'd6f2b878-181f-4584-a595-babdbcac4298'
    # requestverificationtoken = ('CfDJ8ItFsDhqkWRIiWYGIDDs_SNgxmgfhD56DbAIkFZ2x'
    #                             '-G_BLAWvaAWUiYm75m8DKc99fNhW62UTirqnjLTmnY8lDUqmx7f02mRIdVQ38X82gBf_5c6ZRnqE6l3cQfyfDLjet8gqWw1lEhI80wZKU9yeM-2l9iXHuV5EXK5CLm31d8ZYQAOy0V6sgX3j_olXLSJfg')
    # target_date = '2024-03-28'
    # is_has = get_available_appointment_dates(cookies=cookies, target_date=target_date, locationId=locationId,
    #                                          categoryId=categoryId, visaType=visaType, visaSubType=visaSubType,
    #                                          token=requestverificationtoken)
    # if is_has:
    #     slots = get_available_slots_by_date(cookies=cookies, appointmentDate=target_date, locationId=locationId,
    #                                         categoryId=categoryId, visaType=visaType, visaSubType=visaSubType,
    #                                         token=requestverificationtoken)
    #     print(slots)

    # cookies = {
    #     '.AspNetCore.Antiforgery.BDmv0qjjHrI': 'CfDJ8ItFsDhqkWRIiWYGIDDs_SOE2ssT4pPcbQzMBx94rmMC5n52PiDLEKShcibzihHjSCbaTGA3V03tmBNaxGL6NlCUJeqlhTo7Sw48NfuyEtrcliCCBXIf3GPrVgwQatuC0zGfwyaAm2D_BVcvHWrkJK0',
    #     '.AspNetCore.Cookies': 'CfDJ8ItFsDhqkWRIiWYGIDDs_SPqKYinNfyKk9ZImFyFKUBds704IxTeQzYBn5ZtpY5XxMpLU6gSkjJrYsvAlrxWJul7S5LNcAsE0D7pmp4W5zHeSVZaaqvNyvIuoZCJKEC0mhFfYB3xOtUGl-2IbpHTxPX7VQvdXbVylFxn7VoY-YBbYIhwnd5xQPkFUBANJmVomE2q5OJnPAzyg7PKAAxopT8nJPHDe8w_TQTFpYk-4EhxWaQVjtWu8yFrQUJGx0TEh3eJ5hA2EEJqRmniJgSEr6IE9h6CQ5K0E06OcVSu_sTPeV3UOYNtOktUDaWXHb2XSY5C3Fc0-yfnuP1-zAc6Id8S7UWs2SA7zUk9H8eMLCk5tSGJaqxChQMgMxRyNyw95_-CT45fqWVwL9VO_6akdECh7JYc-oEKgncfqZxQVUngt_qOfZ8lMYg_vqn9uNu8NGVTezF2XJiddKml7ux-ev9-DYo06ji_axDJszOu_zfn7s91Ns144JmtprZA_EFPO1tRFoWiAThDDl821Cw7xvZVyRMpP5-5KF0qo7DN7rxpCBOySgD1luSH7vI99mKoKuueO4vGCuu6vcKqXUhZILSjG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6AXdx-10Q1DeSiCL4w4bnHWEJiwsNzhsws_-TPVaN2oXiEQCvGvHm_Fbt0_vKhwMdpP6jpqGOzDhfZ9t2PtyzOrrdqTtO9kaT6oCfh3_Gem8HhMfifjwaRTmBiG7UqjK2k5btpfoWCORgEsLLOWsBcUFuaMwgo13h6JIDqMzkCiAMWGH8eohm9jux0OaVw6JzTRupR_m-0buAEyyvBJimQ0FIEWVczYUGQgZwSl43k0XQD8RNz_oSCCpV8tcsRPtwxNabgowwiGPHY40bTRH-ncgwZQsjOLmPBrTo152fzOOpqe3exQ_iojV6CgvTuWFfxBsU0XHV-LLkfGUBg4o_t8pYt76Eq5liNIX3o3VLl_bZXghKWhTSee5GRa66kmCDWdkWCYQRGAMHylRly8ESHx4fWNny6sJXK-d7Xzn9zuyoawMxDRxTI20dXDLKcTJlXlDinGYZBwspb6BwbywcuVjKNkZY-SxgeFRfK6vsk_ZY0JN5IpGHT-VlYHWHE2y7oNezI-TDVEXkISW3kmdMkXRJWher_jdj-9PCW0UNx-Aa7RWe2MKz-gjd4C4Qd72fH5ecYmPvNjoYqindBdXvD7rwoDL-TI5AdNJRtrVBWFiTkm-FIDwLRxqxHQ9UXq6CZfTB44IwVNc-w-8Ug47i-QCV_--0lkUkWkVJyR6IfqFldK5C6-8fcF8uEfhSKVFuwk'
    # }
    # headers = {
    #     'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
    #     'X-Requested-With': 'XMLHttpRequest'
    # }
    # url = 'https://spain.blscn.cn/CHN/blsAppointment/ManageAppointment?appointmentFor=Individual&applicantsNo=1&visaType=3033c6d3-579b-47e1-9602-91368d63025c&visaSubType=d6f2b878-181f-4584-a595-babdbcac4298&appointmentCategory=5c2e8e01-796d-4347-95ae-0c95a9177b26&location=8d780684-1524-4bda-b138-7c71a8591944&missionId=&data=gTzwyQKIHj9H8We%2fuSzlsymnNeC9LtZqf6zhSYuCZKQwkyPzAM%2fJaJUjEoBtofTCVjtN%2fX8INuAu4JgHx8CEQYm2OFGXDAyItjkeyLI7Z61kN81TYGzRlHq9NUyi3FuQUjAEjwmBFe3%2bOnif%2b9DobX2%2bsj21SQKLrbNxd7rcczA%3d'
    # res = requests.get(url, headers=headers, cookies=cookies)
    # print(res)
    # create_appointment(cookies)
